﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace APP.IO
{
    public enum FolderType
    {
        Temp,
        Configs,
        Logs,
    }

    public class PathHelper
    {
        string configDirPath = PathHelper.GetPath(FolderType.Configs);

        public static string GetPath(FolderType folderType, params string[] combines)
        {
            var mainFolder = GetPath(folderType);
            List<string> list = new List<string>();
            list.Add(mainFolder);
            list.AddRange(combines);
            var folder = Path.Combine(list.ToArray());
            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }

            return folder;
        }

        public static string GetPath(FolderType folderType)
        {
            
            var mainFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            var iBotFolder = Path.Combine(mainFolder, "MyAPP", folderType.ToString());
            return iBotFolder;
        }

        public static string GetTempFileName(string folder, string extension = ".temp")
        {
            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }

            string tempFileFullName = "";
            do
            {
                tempFileFullName = Path.Combine(folder, Guid.NewGuid().ToString("N").Substring(0, 6) + extension);
            }
            while (File.Exists(tempFileFullName));
            return tempFileFullName;
        }


        public static string MoveFileFolder(string oldfile, string Folder, bool copy = false)
        {
            if (!File.Exists(oldfile))
            {
                return null;
            }
            var fileName = Path.GetFileName(oldfile);
            var newFilePath = Path.Combine(Folder, fileName);
            if (!Directory.Exists(Folder))
            {
                Directory.CreateDirectory(Folder);
            }
            System.IO.Path.ChangeExtension(oldfile, ".png");
            if (copy)
            {
                File.Copy(oldfile, newFilePath, true);
            }
            else
            {
                File.Move(oldfile, newFilePath);
            }
            return newFilePath;
        }
    }
}
